#include "StdAfx.h"
#include "SphereBuilder.h"
#include <BRepPrimAPI_MakeSphere.hxx> 
#include "VarList.h"
#include "labelTools.h"
#include "ShapeInfoFactory.h"

REGISTERE_SHAPEINFO(CSphereInfo, SPHERE_CR_GUID);
//////////////////////////////////////////////////////////////////////////
CSphereInfo::CSphereInfo():dRadius(0)
{
	m_szGUID = SPHERE_CR_GUID;
}
CSphereInfo::~CSphereInfo()
{
}
void CSphereInfo::Reset()
{
	dRadius = 0;
}
void CSphereInfo::GetParams(CVarList& varList, UINT nID)
{
	varList.SetID(SPHERE_CR_GUID);
	varList.SetValue(CENTER_POINT, ptCenter);
	varList.SetValue(RADIUS, dRadius);
}
void CSphereInfo::SetParams(const CVarList& varList, UINT nID)
{
	CPointProxy point;
	varList.GetValue(CENTER_POINT, point);
	ptCenter = point;
	varList.GetValue(RADIUS, dRadius);
}
bool CSphereInfo::GetFromLabel(TDF_Label& label)
{
	TDF_Label childLabel;
	if(!LabelTools::GetChild(label, CENTER_POINT, ptCenter, childLabel))
		return false;

	if(!LabelTools::GetChild(label, RADIUS, dRadius, childLabel))
		return false;

	return true;
}

void CSphereInfo::AddToLabel(TDF_Label& label)
{
	LabelTools::SetChild(label, CENTER_POINT, ptCenter);
	LabelTools::SetChild(label, RADIUS, dRadius);
}

bool CSphereInfo::ModifyLabel(TDF_Label& label, TFunction_Logbook& log)
{
	if(!LabelTools::UpdateChild(label, CENTER_POINT, ptCenter, log))
		return false;

	if(!LabelTools::UpdateChild(label, RADIUS, dRadius, log))
		return false;

	return true;
}

bool CSphereInfo::IsModified(TDF_Label& label,const TFunction_Logbook& log)
{
	if(log.IsModified(label.FindChild(CENTER_POINT)))
		return true; 

	if(log.IsModified(label.FindChild(RADIUS)))
		return true; 

	return false;
}
//////////////////////////////////////////////////////////////////////////
CSphereBuilder::CSphereBuilder(void)
{
}

CSphereBuilder::~CSphereBuilder(void)
{
}

bool CSphereBuilder::Build(const CString& szCmdParam, TopoDS_Shape& shape)
{
	return false;
}

bool CSphereBuilder::Build(CSphereInfo* pShapeInfo, TopoDS_Shape& shape)
{
	try
	{
		BRepPrimAPI_MakeSphere builder(pShapeInfo->ptCenter, pShapeInfo->dRadius);
		shape = builder.Shape();
	}
	catch (...) 
	{
		return false;
	}

	return true;
}